package com.wmeimob.fastboot.jiubei.service;

import com.wmeimob.fastboot.jiubei.entity.ShopGoodsStatistics;
import com.wmeimob.fastboot.jiubei.mapper.ShopGoodsStatisticsMapper;
import com.wmeimob.fastboot.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName ShopGoodsStatisticsServiceImpl
 * @Description  商品统计 服务类实现
 * @Author wjt
 * @Date Mon Sep 07 00:55:01 CST 2020
 * @version 1.0
 **/

@Service
@Transactional(rollbackFor={Exception.class})
@Slf4j
public class ShopGoodsStatisticsServiceImpl implements ShopGoodsStatisticsService {

    @Resource
    private ShopGoodsStatisticsMapper shopGoodsStatisticsMapper;


    @Override
    public List<ShopGoodsStatistics> list(ShopGoodsStatistics shopGoodsStatistics) {
        Example example = new Example(ShopGoodsStatistics.class);
        Example.Criteria criteria = example.createCriteria();
	  if(!StringUtils.isEmpty(shopGoodsStatistics.getId())){
            criteria.andEqualTo("id",shopGoodsStatistics.getId());
	  }
	  if(!StringUtils.isEmpty(shopGoodsStatistics.getType())){
            criteria.andLike("type",StringUtils.fullFuzzy(shopGoodsStatistics.getType()));
	  }
	  if(!StringUtils.isEmpty(shopGoodsStatistics.getName())){
            criteria.andLike("name",StringUtils.fullFuzzy(shopGoodsStatistics.getName()));
	  }
	  if(!StringUtils.isEmpty(shopGoodsStatistics.getShopGoodsId())){
            criteria.andEqualTo("shopGoodsId",shopGoodsStatistics.getShopGoodsId());
	  }
	  if(!StringUtils.isEmpty(shopGoodsStatistics.getSpecification())){
            criteria.andLike("specification",StringUtils.fullFuzzy(shopGoodsStatistics.getSpecification()));
	  }
	  if(!StringUtils.isEmpty(shopGoodsStatistics.getUnit())){
            criteria.andLike("unit",StringUtils.fullFuzzy(shopGoodsStatistics.getUnit()));
	  }
	  if(!StringUtils.isEmpty(shopGoodsStatistics.getSalesVolume())){
            criteria.andEqualTo("salesVolume",shopGoodsStatistics.getSalesVolume());
	  }
	  if(!StringUtils.isEmpty(shopGoodsStatistics.getSaleNum())){
            criteria.andEqualTo("saleNum",shopGoodsStatistics.getSaleNum());
	  }
	  if(!StringUtils.isEmpty(shopGoodsStatistics.getDel())){
            criteria.andEqualTo("del",shopGoodsStatistics.getDel());
	  }
	  if(!StringUtils.isEmpty(shopGoodsStatistics.getGmtCreate())){
            criteria.andEqualTo("gmtCreate",shopGoodsStatistics.getGmtCreate());
	  }
	  if(!StringUtils.isEmpty(shopGoodsStatistics.getGmtModified())){
            criteria.andEqualTo("gmtModified",shopGoodsStatistics.getGmtModified());
	  }
	  criteria.andEqualTo("del",false);
        example.orderBy("id").desc();
        List<ShopGoodsStatistics> shopGoodsStatisticss = shopGoodsStatisticsMapper.selectByExample(example);
        return shopGoodsStatisticss;
    }

    @Override
    public ShopGoodsStatistics queryShopGoodsStatisticsById(Object id) {
        return shopGoodsStatisticsMapper.selectByPrimaryKey(id);
    }


	@Override
    public void addShopGoodsStatistics(ShopGoodsStatistics shopGoodsStatistics) {
	  shopGoodsStatistics.setGmtCreate(new Date());
        shopGoodsStatisticsMapper.insertSelective(shopGoodsStatistics);
    }

    @Override
    public void removeShopGoodsStatistics(Object id) {
	  ShopGoodsStatistics shopGoodsStatistics = new ShopGoodsStatistics();
	  shopGoodsStatistics.setId(Integer.parseInt(id.toString()));
	  shopGoodsStatistics.setDel(true);
        shopGoodsStatisticsMapper.updateByPrimaryKeySelective(shopGoodsStatistics);
    }

    @Override
    public void modifyShopGoodsStatistics(ShopGoodsStatistics shopGoodsStatistics) {
		shopGoodsStatistics.setGmtModified(new Date());
        shopGoodsStatisticsMapper.updateByPrimaryKeySelective(shopGoodsStatistics);
    }

}
